Get name mangling when I try to use exceptions [CodeBlocks, C++]

Posted by Beetroot on Stack Overflow See other posts from Stack Overflow or by Beetroot
Published on 2012-09-02T08:51:54Z Indexed on 2012/09/02 9:38 UTC
Read the original article Hit count: 172

Filed under:
|
|

I am trying to use exceptions for the first time but even though it is quite a simple example I just cannot get it to compile, I have looked at several examples and tried coding it in many, many different ways but I am still not even sure exactly where the problem is because I get namemangling when I introduce the catch/try/throw anyway here is my code hopefully it is something really stupid :)

#include "Surface.h"
#include "SDL_Image.h"

using namespace std;

SDL_Surface* surface::Load(string fileName){

   SDL_Surface* loadedSurface = IMG_Load(fileName.c_str());
   if(loadedSurface == 0) throw 0;

   //Convert surface to same format as display
   loadedSurface = SDL_DisplayFormatAlpha(loadedSurface);

   return loadedSurface;
}

#include "GameState.h"
#include "Surface.h"

#include<iostream>

using namespace std;

GameState::GameState(string fileName){

   try{
      stateWallpaper_ = surface::Load(fileName);
   }
   catch(int& e){
      cerr << "Could not load " << fileName << endl;
   }
}

Thanks in advance for any help!

EDIT: Sorry I forgot to post the error message: It is

In function `ZN14GameStateIntroC1Ev':|
-undefined reference to `__gxx_personality_sj0'|
-undefined reference to `_Unwind_SjLj_Register'|
-undefined reference to `_Unwind_SjLj_Unregister'|
In function `ZN14GameStateIntroC1Ev':|
undefined reference to `_Unwind_SjLj_Resume'|
In function `ZN14GameStateIntroC2Ev':|
-undefined reference to `__gxx_personality_sj0'|
-undefined reference to `_Unwind_SjLj_Register'|
-undefined reference to `_Unwind_SjLj_Unregister'|
obj\Release\GameStateIntro.o||In function `ZN14GameStateIntroC2Ev':|
C:\Program Files (x86)\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\ext\new_allocator.h|69|undefined reference to `_Unwind_SjLj_Resume'|
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `redirect_output':|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|219|undefined reference to `SDL_strlcpy'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|220|undefined reference to `SDL_strlcat'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|243|undefined reference to `SDL_strlcpy'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|244|undefined reference to `SDL_strlcat'|
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `console_main':|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|296|undefined reference to `SDL_strlcpy'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|301|undefined reference to `SDL_GetError'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|312|undefined reference to `SDL_SetModuleHandle'|
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `WinMain@16':|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|354|undefined reference to `SDL_getenv'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|386|undefined reference to `SDL_strlcpy'|
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `cleanup':|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|158|undefined reference to `SDL_Quit'|

**

© Stack Overflow or respective owner

Related posts about c++

Related posts about exception